// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HorizontalDepthProfile.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Robotics.Navigation.Perception
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using Microsoft.Robotics.Numerics;

    /// <summary>
    /// Interface that represents a generalized form of scan line.
    /// </summary>
    /// <remarks>This is an interface rather than an abstract class to allow the compiler to inline the point-wise methods. </remarks>
    public interface IHorizontalDepthProfile
    {
        /// <summary>
        /// Gets the number of entries (bins) in the horizontal depth profile.
        /// </summary>
        int Length { get; }

        /// <summary>
        /// Gets the pose of the center of the horizontal depth profile.  
        /// </summary>
        Pose2D Pose { get; }

        /// <summary>
        /// Gets the angular field of view of the depth profile
        /// </summary>
        double FOV { get; }

        /// <summary>
        /// Gets the maximum distance in the scan line
        /// </summary>
        double MaximumDistance { get; }

        /// <summary>
        /// Returns the maximum width of the field of view given a depth cutoff distance.
        /// </summary>
        /// <param name="maxDepth">The maximum depth distance</param>
        /// <returns>The width of the field of view at the given depth</returns>
        double GetFOVWidthForDepth(double maxDepth);

        /// <summary>
        /// Returns the angle of the ray corresponding to the given index.
        /// </summary>
        /// <param name="index">The index of a depth value of hit points</param>
        /// <returns>The corresponding angle.</returns>
        double GetAngleForIndex(int index);

        /// <summary>
        /// Returns the distance to the closest obstacle along the specified ray (distance is measured to the focal point, i.e. along the ray).
        /// </summary>
        /// <param name="index">Index of the ray / pixel</param>
        /// <returns>The distance to the obstacle along the given ray / pixel</returns>
        double GetHitDistance(int index);

        /// <summary>
        /// Returns the closest occupied point in the sensor coordinate frame for the given ray / pixel index
        /// </summary>
        /// <param name="index">Index of the ray / pixel</param>
        /// <returns>The coordinates of the closest occupied point in the sensor coordinate frame</returns>
        Point2D GetHitPoint(int index);

        /// <summary>
        /// Adds an observed obstacle specified in local coordinates.
        /// Has no effect if the profile already contains a smaller depth value at that heading.
        /// </summary>
        /// <param name="observation">The observation to add, in local sensor coordinates (x represents depth, along the optical axis, y is positive to the left of the optical axis).</param>
        void AddHitPoint(Point2D observation);

        /// <summary>
        /// Returns the index of the ray/pixel on which the specified point falls and the distance along the ray to the point
        /// </summary>
        /// <param name="localPoint">The point to re-project, in local coordinates</param>
        /// <param name="distance">The distance along the ray to the specified point</param>
        /// <returns>The index of the ray/pixel corresponding to the specified point, or -1 if the point is outside of the field of view</returns>
        int Reproject(Point2D localPoint, out double distance);

        /// <summary>
        /// Creates an empty horizontal depth profile with the same pose and structure as this one.
        /// </summary>
        /// <returns>An empty depth profile</returns>
        IHorizontalDepthProfile Create();
    }
}
